Aller au contenu principal

Transformation

Matrice​

La matrice permet d'effectuer n'importe quelle transformation en appliquant sur les coordonnées de la forme d'origine 2 équations.

x′=a×x+c×y+ex' = a\times x + c\times y + e y′=b×x+d×y+fy' = b\times x + d\times y + f

la fonction matrice possède 6 paramètres matrix(a b c d e f)

Transformation=[ace bdf]Transformation = \begin{bmatrix} a & c & e \\\ b & d & f \end{bmatrix}

Translation​

<rect transform="translate(30, 40)" />
<rect transform="matrix(1, 0, 0, 1, 30, 40)" />
Translation=[1030 0140]Translation = \begin{bmatrix} 1 & 0 & 30 \\\ 0 & 1 & 40 \end{bmatrix} x′=x+30x' = x + 30 y′=y+40y' = y + 40

Rotation​

<rect transform="rotate(45)" />
<rect transform="matrix(cos(a), sin(a), -sin(a), cos(a), 0, 0)" />
Rotation=[cos(α)−sin(α)0 sin(α)cos(α)0]Rotation = \begin{bmatrix} cos(\alpha) & -sin(\alpha) & 0 \\\ sin(\alpha) & cos(\alpha) & 0 \end{bmatrix} x′=x×cos(α)−y×sin(α)x' = x\times cos(\alpha) - y\times sin(\alpha) y′=x×sin(α)+y×cos(α)y' = x\times sin(\alpha) + y\times cos(\alpha)

Échelle​

<rect transform="scale(0.5)" />
<rec transform="matrix(0.5, 0, 0, 0.5, 0, 0)" />
Eˊchelle=[0.500 00.50]Échelle = \begin{bmatrix} 0.5 & 0 & 0 \\\ 0 & 0.5 & 0 \end{bmatrix} x′=x×0.5x' = x\times0.5 y′=y×0.5y' = y\times0.5

Inclinaison ou cisaillement​

<rect transform="skewX(-15)" />
Inclinaison=[1tan(α)0 010]Inclinaison = \begin{bmatrix} 1 & tan(\alpha) & 0 \\\ 0 & 1 & 0 \end{bmatrix} x′=x+y×tan(α)x' = x + y\times tan(\alpha) y′=yy' = y

Y​

Inclinaison=[100 tan(α)10]Inclinaison = \begin{bmatrix} 1 & 0 & 0 \\\ tan(\alpha) & 1 & 0 \end{bmatrix} x′=x+y×tan(α)x' = x + y\times tan(\alpha) y′=yy' = y

Multiples transformations​

Les transformations peuvent être combinés en les ajoutant les unes à la suite des autres.

Attention toutefois le système de coordonnées tout entier est transformé lui aussi

<rect transform="rotate(30) translate(0, 40) " />

Le déplacement en x de 40px s'effectue suivant le nouvel axe x qui a subit lui aussi une rotation de 30°

Multiplication de matrice​

La multiplication de matrice s'effectue en

Resultant=[ace bdf 001]×[a′c′e′ b′d′f′ 001]=[a×a′+c×b′a×c′+c×d′a×e′+c×f′+e b×a′+d×b′b×c′+d×d′b×e′+d×f′+f 001]Resultant = \begin{bmatrix} a & c & e \\\ b & d & f \\\ 0 & 0 & 1 \end{bmatrix} \times \begin{bmatrix} a' & c' & e' \\\ b' & d' & f' \\\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} a\times a' + c \times b' & a \times c' + c \times d' & a \times e' + c \times f' + e \\\ b\times a' + d \times b' & b \times c' + d \times d' & b \times e' + d \times f' + f \\\ 0 & 0 & 1 \end{bmatrix} Transformation=[cos(30)−sin(30)0 sin(30)cos(30)0 001]×[1040 010 001]=[cos(30)−sin(30)cos(30)×40 sin(30)cos(30)sin(30)×40 001]Transformation = \begin{bmatrix} cos(30) & -sin(30) & 0 \\\ sin(30) & cos(30) & 0 \\\ 0 & 0 & 1 \end{bmatrix} \times \begin{bmatrix} 1 & 0 & 40 \\\ 0 & 1 & 0 \\\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} cos(30) & -sin(30) & cos(30) \times 40 \\\ sin(30) & cos(30) & sin(30) \times 40 \\\ 0 & 0 & 1\end{bmatrix}

Origine de la transformation​

la propriété transform-origin permet de sélectionner l'origine de la transformation. C'est très utile dans le cas des rotations.

<rect x="50" y="25" width="100" height="100"
transform="rotate(45)" transform-origin="100 75"/>

L'origine de la transformation est située au milieu du carré.

Projection isométrique